package com.lgt_enterprise_android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.lgt_enterprise_android.R;
import com.lgt_enterprise_android.base.MyBaseAdapter;
import com.lgt_enterprise_android.utils.CommonUtil;
import com.lgt_enterprise_android.utils.StringUtil;

public class MyStaffAdapter2 extends MyBaseAdapter {

    public MyStaffAdapter2(Context _mContext, JSONArray _mArray){
        super(_mContext,_mArray);
    }

//    @Override
//    public int getViewTypeCount() {
//        // menu type count
//        return 2;
//    }
//

//
//
//    public String getStaffIdByPos(int pos){
//        JSONObject jsonObject=mArray.getJSONObject(pos);
//        return jsonObject.getJSONObject("workerInfo").getString("id");
//    }


    @Override
    public View getView(int pos, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_staff2, null);
            holder.txtName = (TextView) convertView.findViewById(R.id.txt_name);
            holder.txtProp = (TextView) convertView.findViewById(R.id.txt_prop);
//            holder.txtStatus = convertView.findViewById(R.id.txt_status);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        JSONObject jsonObject=mArray.getJSONObject(pos);

        JSONObject staffJsonObj=jsonObject.getJSONObject("workerDO");

        holder.txtName.setText(staffJsonObj.getString("name"));

        String genderStr= CommonUtil.getGenderStr(staffJsonObj.getIntValue("gender"));
        String goodAT="";
        JSONArray jsonArray=jsonObject.getJSONArray("workerTagDOList");

        for(int i=0;i<jsonArray.size();i++){
            JSONObject jo=jsonArray.getJSONObject(i);
            goodAT+=jo.getString("tagContent")+"/";
        }

        if(goodAT.length()>0){
            goodAT=goodAT.substring(0,goodAT.length()-1);
        }

        String age=staffJsonObj.getString("age");
        if(StringUtil.isEmpty(age)){
            age="";
        }else{
            age+="/";
        }

        holder.txtProp.setText(age+genderStr+"/"+goodAT);

//        holder.txtStatus.setVisibility(View.GONE);

        return convertView;
    }

    public class ViewHolder {
        public TextView txtName;
        public TextView txtProp;
//        public View txtStatus;
    }
}
